<template>
  <div class="Login h-100vh flex flex-column ai-center jc-center">
    <el-card class="w-288">
      <div slot="header" class="flex jc-center">
        <span class="pointer flex-sub text-center color-blue">登录</span>
      </div>
      <el-form :model="form">
        <el-form-item label="账号"><el-input type="text" v-model="form.account"></el-input></el-form-item>
        <el-form-item label="密码">
          <el-input type="password" @keyup.enter.native="Login" v-model="form.password"></el-input>
        </el-form-item>
      </el-form>
    </el-card>
    <el-button class="w-288 h-40" :loading="Loading" @click="Login" type="primary"> 登录 </el-button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: { account: "", password: "" },
      Loading: false,
    };
  },
  methods: {
    Login() {
      this.Loading = true;
      this.$api.post("/Login", this.form).then(({ data }) => {
        if (data.Code == 200) {
          this.$message.success(data.Msg);
          localStorage.setItem("Token", data.Token);
          localStorage.setItem("name", data.data);
          this.$router.push("/");
        } else this.$message.error(data.Msg);
        this.Loading = false;
      });
    },
  },
  created() {
    localStorage.clear();
  },
};
</script>

<style lang="less"></style>
